/**
 * JAVACC DEMO 1.0
 * @copy right apache company All rights reserved. 
 * @Package com.apache.task.impl  
 */
package com.apache.portal.task;

import java.lang.reflect.Method;
import java.util.Calendar;

import com.apache.database.model.TaskEntity;
import com.apache.tools.StrUtil;

/**
 * description:  实现Runable接口，线程池中调用
 * @author Hou Dayu 创建时间：2016-1-14
 * @Copyright(c)2014:
 */
public class TaskRunnable implements Runnable {

	private TaskEntity task;

	public TaskRunnable() {
	}

	public TaskRunnable(TaskEntity task) {
		this.task = task;
	}

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see java.lang.Runnable#run()  
	 */
	public void run() {
		try {
			int count = Calendar.getInstance().getTime().getHours();
			boolean flag = false;
			if (0 == task.getStartTime() && 0 == task.getEndTime()) {
				flag = true;
			} else if (0 == task.getStartTime() && 0 < task.getEndTime()) {
				flag = count <= Integer.valueOf(task.getEndTime());
			} else if (0 < task.getStartTime() && 0 < task.getEndTime()) {
				flag = task.getStartTime() <= count && count <= task.getEndTime();
			}
			if (flag) {
				Class<?> classType = Class.forName(task.getClassName());
				Method getMethod = classType.getMethod("run");
				Object obj = getMethod.invoke(classType.newInstance());
				if (StrUtil.isEmpty(obj)) {
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
